package com.rabbit.eap.framework.config.jackson.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.rabbit.eap.common.lang.LocalDateTimeUtils;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * @projectName eap
 * @packageName com.rabbit.eap.framework.config.jackson.serializer
 * @className JacksonDateSerializer
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/4/27 20:55
 * <p>Description: JacksonDateSerializer </p>

 */
public class JacksonDateSerializer extends JsonSerializer<LocalDateTime> {
    @Override
    public void serialize(LocalDateTime date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        String string = null;
        if (date != null) {
            string = LocalDateTimeUtils.getDateTime(date);
        }
        jsonGenerator.writeString(string);
    }
}
